using System;
using System.Collections.Generic;
using TTDotNet.Engine.Industries;

namespace TTDotNet.Engine
{
    public enum CargoType { None, Passengers, Coal, Mail, Oil, Livestock, Goods, Grain, Wood, Iron_Ore, Steel, Valuables, Copper_Ore, Food, Water, Fruit, Rubber};

    public static class Cargo
    {
        private static Dictionary<CargoType, string> units;

        static Cargo()
        {
            units = new Dictionary<CargoType, string>();

            units[CargoType.Coal] = "tonnes";
            units[CargoType.Copper_Ore] = "tonnes";
            units[CargoType.Food] = "tonnes";
            units[CargoType.Fruit] = "tonnes";
            units[CargoType.Goods] = "crates";
            units[CargoType.Grain] = "tonnes";
            units[CargoType.Iron_Ore] = "tonnes";
            units[CargoType.Livestock] = "items";
            units[CargoType.Mail] = "bags";
            units[CargoType.None] = "";
            units[CargoType.Oil] = "litres";
            units[CargoType.Passengers] = "passengers";
            units[CargoType.Rubber] = "litres";
            units[CargoType.Steel] = "tonnes";
            units[CargoType.Valuables] = "bags";
            units[CargoType.Water] = "litres";
            units[CargoType.Wood] = "tonnes";
        }

        

        public static string GetUnitName(CargoType type)
        {
            return units[type];
        }

        public static string GetQuantityAndUnit(CargoType type)
        {
            if (type != CargoType.Passengers)
            {
                return units[type] + " of " + type.ToString().Replace("_", " ");
            }
            else
            {
                return "passengers";
            }
        }

    }

    public struct CargoInfo
    {
        private CargoType cargo;
        private float amount;

        public CargoInfo(CargoType cargo, float amount)
        {
            this.cargo = cargo;
            this.amount = amount;
        }

        public CargoType Cargo
        {
            get { return cargo; }
        }

        public float Amount
        {
            get { return amount; }
        }
    }

    public struct CargoPacket
    {
        private CargoInfo packet;
        private DateTime datePickedUp;
        private Industry sourceIndustry;

        public CargoPacket(CargoInfo packet, DateTime pickedUp, Industry source) 
        {
            this.packet = packet;
            datePickedUp = pickedUp;
            sourceIndustry = source;
        }

        public CargoType CargoType
        {
            get { return packet.Cargo; }
        }

        public float CargoAmount
        {
            get { return packet.Amount; }
        }

        public DateTime DatePickedUp
        {
            get { return datePickedUp; }
        }

        public Industry SourceIndustry
        {
            get { return sourceIndustry; }
        }

        public static float WaitingAmount(List<CargoPacket> list)
        {
            float carrying = 0;

            foreach (CargoPacket packet in list)
            {
                carrying += packet.CargoAmount;
            }

            return carrying;
        }

    }

}
